$(function() {
    var num1 = "";
    var num2 = "";
    var char = "";
    var result = "";
    var falg = false;
    $(".number").on("click", function() {
        // console.log($(this).text());
        var value = $(this).text();
        if (char == "") {
            if (falg) {
                num1 = "";
                num2 = "";
                falg = false;
            }
            num1 = num1 + value;
            // console.log(num1);
            $(".count").val(num1);
        } else {
            num2 += value;
            $(".count").val(num1 + char + num2);
        }
    });
    $(".ysf").click(function() {
        if (num2) {
            switch (char) {
                case "+":
                    result = parseFloat(num1) + parseFloat(num2);
                    break;
                case "-":
                    result = parseFloat(num1) - parseFloat(num2);
                    break;
                case "*":
                    result = parseFloat(num1) * parseFloat(num2);
                    break;
                case "/":
                    result = parseFloat(num1) / parseFloat(num2);
                    break;
                case "%":
                    result = parseFloat(num1) % parseFloat(num2);
                    break;
                case "平方":
                    result = parseFloat(num1 + num2) * parseFloat(num1 + num2);
                    $(".count").val(result);
                    break;
                case "开方":
                    result = Math.sqrt(parseFloat(num1 + num2));
                    $(".count").val(result);
                    break;
            }
            num1 = result;
            num2 = "";
        }
        char = $(this).text();
        $(".count").val(num1 + char);
    });
    $(".result").click(function() {
        // console.log(char);
        if (char == "") {
            $(".count").val(result);
        }
        switch (char) {
            case "+":
                result = parseFloat(num1) + parseFloat(num2);
                break;
            case "-":
                result = parseFloat(num1) - parseFloat(num2);
                break;
            case "*":
                result = parseFloat(num1) * parseFloat(num2);
                break;
            case "/":
                result = parseFloat(num1) / parseFloat(num2);
                break;
            case "%":
                result = parseFloat(num1) % parseFloat(num2);
                break;
            case "平方":
        }
        $(".count").val(result);
        num1 = result;
        char = "";
        falg = true;
    });
    $(".pf").click(function() {
        char = $(this).text();
        result = parseInt(num1) * parseInt(num1);
        $(".count").val(result);
        num1 = result;
    });
    $(".kf").click(function() {
        char = $(this).text();
        result = Math.sqrt(parseInt(num1));
        $(".count").val(result);
        num1 = result;
    });
    $(".clear").click(function() {
        result = "";
        num1 = "";
        num2 = "";
        char = "";
        $(".count").val(0);
    });
});